Use new MSVC preprocessor for VS 17 builds #15201
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From the documentation[1]:
| We're updating the Microsoft C++ preprocessor to improve standards | conformance, fix longstanding bugs, and change some behaviors that | are officially undefined. We've also added new diagnostics to warn | on errors in macro definitions.
Thus it appears to be sensible to switch to the new preprocessor for all VS17 builds. Note that although the new preprocessor is available as of VS16.5 (i.e.
version >= 1925
), we don't want to potentially break older builds, and as such use the new preprocessor only for VS17 builds. Users who wish to use the new preprocessor with VS16, can stillset CFLAGS=/Zc:preprocessor
before runningbuildconf
/phpize
.[1] https://learn.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview?view=msvc-170
Note that I was reminded of this when re-checking krakjoe/cmark#20, and the new preprocessor was quite helpful in directly triggering a useful C5101 diagnostic, instead of triggering C2121 and C2059.
This change might break builds of older PHP versions with VS17, but those users can counteract via
set CFLAGS=/Zc:preprocessor-
, or just fix the code for best (forward) compatibility.